package cn.wolfcode.rbac.service.impl;

import cn.wolfcode.rbac.domain.Customer;
import cn.wolfcode.rbac.domain.Customertransfer;
import cn.wolfcode.rbac.mapper.CustomerMapper;
import cn.wolfcode.rbac.query.QueryObject;
import cn.wolfcode.rbac.service.ICustomerReportService;
import cn.wolfcode.rbac.service.ICustomerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class CustomerServiceImpl implements ICustomerService {
    @Autowired
    private CustomerMapper customerMapper;

    @Override
    @Transactional(readOnly = true)
    public PageInfo list(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Customer> list = customerMapper.selectAll(qo);
        return new PageInfo(list);
    }

    @Override
    public PageInfo fialList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Customer> list = customerMapper.failList(qo);
        return new PageInfo(list);
    }

    @Override
    public PageInfo potentialList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Customer> list = customerMapper.potentialList(qo);
        return new PageInfo(list);
    }

    @Override
    public PageInfo poolList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Customer> list = customerMapper.poolList(qo);
        return new PageInfo(list);
    }

    @Override
    public PageInfo officialList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Customer> list = customerMapper.officialList(qo);
        return new PageInfo(list);
    }

    @Override
    public PageInfo turnoverList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Customer> list = customerMapper.turnoverList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(Customer customer) {
        //判断一下是更新还是修改
        if(customer.getId() == null){
            customer.setStatus(0);
            this.customerMapper.insert(customer);
        }else{
            this.customerMapper.update(customer);
        }
    }

    @Override
    public void updateStateById(Long customerId,Integer status) {
        this.customerMapper.updateStateById(customerId,status);
    }

    @Override
    public int absorb(Customertransfer customertransfer) {
        return this.customerMapper.absorb(customertransfer);
    }
}
